package com.senmin.aPrinciple.a3DependenceInversionPrinciple.tdemo1;

/**
 * @className: demeter1
 * @author: xpj
 * @create: 2021/6/5
 * @description: 案例：请编写完成person消息的功能【用依赖倒置】 方式2：通过构造方法来实现依赖
 */
public class demo2 {
    public static void main(String[] args) {
        Changhong2 changhong = new Changhong2();
        OpenAndClose2  openAndClose =  new OpenAndClose2(changhong);
        openAndClose.open();
    }
}

//方式1通过接口来实现依赖
interface IOpenAndClose2 {
    public void open ();//抽象方法，这里没有接收接口
}

interface ITV2{
    public void play();
}

class Changhong2 implements ITV2{
    @Override
    public void play(){
        System.out.println("打开长虹电视打开");
    }
}

//实现接口
class OpenAndClose2 implements  IOpenAndClose2{
    public ITV2 tv;

    public OpenAndClose2(ITV2 tv){
        this.tv = tv;
    }

    @Override
    public  void open(){
        this.tv.play();
    }
}


